package org.dromara.web.plugins.provider;


import org.checkerframework.checker.units.qual.A;
import org.dromara.common.core.exception.user.UserException;
import org.dromara.dao.business.domain.Model;
import org.dromara.dao.business.domain.ModelParam;
import org.dromara.web.plugins.provider.imageImpl.AliyunDashScopeProvider;
import org.dromara.web.plugins.provider.imageImpl.DalleImageProvider;
import org.dromara.web.plugins.provider.imageImpl.SD3ImageProvider;
import org.dromara.web.plugins.provider.imageImpl.SDXLV1ImageProvider;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class TextToImageModelProviderFactory implements InitializingBean {

    private Map<String, TextToImageProvider> providers = new HashMap<>();

    @Autowired
    SD3ImageProvider sd3ImageProvider;
    @Autowired
    DalleImageProvider dalleImageProvider;
    @Autowired
    SDXLV1ImageProvider sdxlv1ImageProvider;
    @Autowired
    AliyunDashScopeProvider aliyunDashScopeProvider;


    @Override
    public void afterPropertiesSet() throws Exception {
        providers.put(SD3ImageProvider.MODEL_TYPE, sd3ImageProvider );
        providers.put(DalleImageProvider.MODEL_TYPE, dalleImageProvider);
        providers.put(SDXLV1ImageProvider.MODEL_TYPE, sdxlv1ImageProvider);
        providers.put(AliyunDashScopeProvider.MODEL_TYPE, aliyunDashScopeProvider);
    }




    public String textToImage(Model model, String prompt, ModelParam modelParam, String scale) {
        TextToImageProvider chatProvider = providers.get(model.getManu());
        if (chatProvider == null) {
            throw new UserException("model.notmatch");
        }
        // 调用相应的api来发送请求
        return chatProvider.generateImage(model, prompt, modelParam, scale);

    }
}
